<template>
  <div class="dialog" v-show="visible">
    <div class="dialog-wrap">
      <div class="dialog-header">
        <slot name="header"></slot>
        <span class="dialog-header-close" @click="btnClose" style="cursor: pointer">X</span>
      </div>
      <div class="dialog-body">
        <slot></slot>
      </div>
      <div class="dialog-footer">
        <slot name="footer"></slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Dialog",
  props: ["visible"],
  methods: {
    btnClose() {
      // this.$emit('close:visible',false)
      this.$emit("update:visible", false)
    },
  },
}
</script>

<style lang="less" scoped>
.dialog {
  // 最外层
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.3);
}

// 内层水平垂直居中
.dialog-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 460px;
  height: 200px;
  box-sizing: border-box; // 内减模式
  padding: 12px;
  transform: translate(-50%, -50%);
  background-color: #fff;
  .dialog-header {
    display: flex;
    font-size: 18px;
    justify-content: space-between;
  }
  .dialog-body {
    font-size: 20px;
    text-align: center;
    height: 70%;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .dialog-footer {
    font-size: 20px;
    position: absolute;
    right: 20px;
    display: flex;
    .btn {
      color: lightyellow;
      font-size: 20px;
      margin-left: 10px;
      border: none;
      background-color: bisque;
      border-radius: 8%;
    }
    .btn:hover {
      background-color: aquamarine;
      color: black;
    }
  }
}
</style>
